import request from '@/utils/request'

export function getRoutes() {
  return request({
    url: '/routes',
    method: 'get'
  })
}

export function getRoles() {
  return request({
    url: '/roles',
    method: 'get'
  })
}

export function addRole(data) {
  return request({
    url: '/role',
    method: 'post',
    data
  })
}

export function updateRole(id, data) {
  return request({
    url: `/role/${id}`,
    method: 'put',
    data
  })
}

export function deleteRole(id) {
  return request({
    url: `/role/${id}`,
    method: 'delete'
  })
}

// 用户密码重置
export function handleResetPwd(name, password) {
  const data = {
    name,
    password,
    isReset: true // 确保添加 isReset 参数用于区分重置操作
  }
  return request({
    url: '/user/password',
    method: 'post',
    data: data
  })
}

// 授权角色
export function getAuthRole(name) {
  return request({
    url: '/user/updateRole' + name,
    method: 'post'
  })
}

